"""
Case Type   : 系统视图
Case Name   : 测试系统视图PG_STAT_USER_INDEXES字段与数据类型
Create At   : 2021/01/06
Owner       : opentestcase015
Description :
    1.查看系统视图PG_STAT_USER_INDEXES的结构
    2.该视图字段与对应字段数据类型是否正确
Expect      :
    1.查看系统视图PG_STAT_USER_INDEXES的结构成功
    2.该视图字段与字段数据类型对应正确
History     :
"""

import unittest

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger

LOG = Logger()


class SystemView(unittest.TestCase):
    def setUp(self):
        LOG.info('----------------this is setup-----------------------')
        LOG.info(
            '---------Opengauss_Function_System_View_Case0047开始执行-------')
        self.com = Common()
        self.comsh = CommonSH('dbuser')
        self.expect_result_dict = {
            'Column': ['relid', 'indexrelid', 'schemaname', 'relname',
                       'indexrelname', 'idx_scan', 'last_idx_scan',
                       'idx_tup_read', 'idx_tup_fetch'],
            'Type': ['oid', 'oid', 'name', 'name', 'name', 'bigint',
                     'timestamp with time zone', 'bigint', 'bigint']}

    def test_index_file_damaged(self):
        LOG.info(
            '----------------------查看表结构-----------------------------')
        msg = self.comsh.execut_db_sql('\d PG_STAT_USER_INDEXES')
        LOG.info(msg)
        result_dict = self.com.format_sql_result(msg)
        LOG.info(result_dict)
        del result_dict['Modifiers']
        self.assertDictEqual(self.expect_result_dict, result_dict)

    def tearDown(self):
        LOG.info('----------------this is tearDown-----------------------')
        # 无须清理环境
        LOG.info(
            '-------Opengauss_Function_System_View_Case0047执行完成--------')
